package com.ruoyi.web.controller.zzwt;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.zzw.LongListDto;
import com.ruoyi.common.core.domain.zzw.TRegionInfo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.service.ITRegionInfoService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区Controller
 *
 * @author xbx
 * @date 2023-10-20
 */
@RestController
@RequestMapping("/system/region")
public class TRegionInfoController extends BaseController {
    @Autowired
    private ITRegionInfoService tRegionInfoService;

    /**
     * 查询地区列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(TRegionInfo tRegionInfo) {
        startPage();
        List<TRegionInfo> list = tRegionInfoService.selectTRegionInfoList(tRegionInfo);
        return getDataTable(list);
    }

    /**
     * 导出地区列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "地区", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TRegionInfo tRegionInfo) {
        List<TRegionInfo> list = tRegionInfoService.selectTRegionInfoList(tRegionInfo);
        ExcelUtil<TRegionInfo> util = new ExcelUtil<TRegionInfo>(TRegionInfo.class);
        util.exportExcel(response, list, "地区数据");
    }

    /**
     * 获取地区详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{cRegionId}")
    public AjaxResult getInfo(@PathVariable("cRegionId") Long cRegionId) {
        return success(tRegionInfoService.selectTRegionInfoByCRegionId(cRegionId));
    }

    /**
     * 新增地区
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "地区", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TRegionInfo tRegionInfo) {
        return toAjax(tRegionInfoService.insertTRegionInfo(tRegionInfo));
    }

    /**
     * 修改地区
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "地区", businessType = BusinessType.UPDATE)
    @PutMapping("/update/{cRegionId}")
    public AjaxResult edit(@RequestBody TRegionInfo tRegionInfo) {
        return toAjax(tRegionInfoService.updateTRegionInfo(tRegionInfo));
    }

    /**
     * 删除地区
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "地区", businessType = BusinessType.DELETE)
    @DeleteMapping("/batchDelete")
    public AjaxResult remove(@RequestBody LongListDto dto) {
        return toAjax(tRegionInfoService.deleteTRegionInfoByCRegionIds(dto.getIds()));
    }
}
